
import { makeAutoObservable } from 'mobx'
import { http } from '@/utils'
// login module
import { getUserToken, setUserToken, removeUserToken } from '@/utils'
class LoginStore {
  token = getUserToken()
  constructor() {
    makeAutoObservable(this)
  }

  getToken = async ({ mobile, code }) => {
    const res = await http.post('http://geek.itheima.net/v1_0/authorizations', {
      mobile,
      code
    })
    setUserToken(res.data.token)
    this.token = res.data
  }
  loginOut = () => {
    removeUserToken()
    this.token = ''
  }
}

export default LoginStore